﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfDemo.IRepository.Sys;
using WpfDemo.Models;
using WpfDemo.Models.Context;
using WpfDemo.Models.Sys;

namespace WpfDemo.Repository.Sys
{
    public class ModuleRepository : BaseRepository<ModuleEntity>, IModuleRepository
    {
        public ModuleRepository(EfContext db) : base(db)
        {
        }

        public List<ModuleDto> GetMenus()
        {
            using(var db = new EfContext())
            {
                var query = from a in db.modules
                            select new ModuleDto()
                            {
                                F_Id = a.F_Id,
                                F_Name = a.F_Name,
                                F_Code = a.F_Code,
                                F_CreateTime = a.F_CreateTime,
                                F_Icon = a.F_Icon,
                                F_IsDisabled = a.F_IsDisabled,
                                F_IsExpanded = a.F_IsExpanded,
                                F_ParentId = a.F_ParentId,
                                F_Remark = a.F_Remark,
                                F_Sort = a.F_Sort,
                                F_TargetView = a.F_TargetView,
                                menus = db.bottons.Where(m => m.F_ModuleId == a.F_Id).Select(m => new ItemCheck()
                                {
                                    IsChecked = false,
                                    Name = m.F_Name,
                                    ButtonId = m.F_Id,
                                }).ToList()
                            };
                return query.ToList();
            }
        }
    }
}
